package A2;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

public class XZ {
    static String url ="https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AATv6tY.img?h=1658&w=1438&m=6&q=60&o=f&l=f";
    static String url1 = "https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png";
    public static void main(String[] args) {
    dwnload();
    }
    static void dwnload(){
        BufferedInputStream out = null;
        BufferedOutputStream in = null;
        HttpURLConnection http = null;
        try {
            URL get = new URL(url);
            http = (HttpURLConnection) get.openConnection();
            InputStream in1 = http.getInputStream();
            out = new BufferedInputStream(in1);
            OutputStream in11 = new FileOutputStream("F:\\JAVA\\A1\\src\\A2\\download.png") ;
            in = new BufferedOutputStream(in11);
            byte[] buff = new byte[1024];

            int i = out.read(buff);
            System.out.println(i);
            while (i!=-1){
                in.write(buff,0,i);

                i=out.read(buff);
            }
        }catch (Throwable r ){
            r.printStackTrace();
        }finally {
            if(out!=null){
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (in!=null){
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(http!=null){
                http.disconnect();
            }
        }
    }
}
